// *******************************************************************************************************
// # INDEX
//   / トップ
// *******************************************************************************************************
this.rjapmn_md = this.rjapmn_md || {};

/*
【初回訪問時のCOOKIE処理について】
- クッキーは3か月保持

（１）質問：住みたい駅名を入力してください
変数rjapmn_md.data.cookieArray[0]に記述してある、'apmnFirstVisitStation'というcookie名で値を保存しています。

（２）質問：ご希望の家賃を選んでください
変数rjapmn_md.data.cookieArray[1]に記述してある、'apmnFirstVisitRent'というcookie名で値を保存しています。

（３）質問：居住人数を選んでください
変数rjapmn_md.data.cookieArray[2]に記述してある、'apmnFirstVisitNumbers'というcookie名で値を保存しています。

▼このjsでの、cookie保存データの取得は下記関数で呼び出せます。
Cookie/駅名=　　　　getFirstVisitCookieStation();
Cookie/家賃=　　　　getFirstVisitCookieRent();
Cookie/居住人数=　getFirstVisitCookieNumbers();

▼Cookieの保存方法について
一度、変数rjapmn_md.data.dataObjに代入した後、apmnSetCookie(cookie名、保存する値)を使って保存しています。

・変数rjapmn_md.data.dataObjへ値の代入箇所
（１）質問：住みたい駅名を入力してください：行数120あたり
（２）質問：ご希望の家賃を選んでください（３）質問：居住人数を選んでください：行数184あたり

・rjapmn_md.data.dataObjデータを実際にCookieに保存している箇所
→　関数：rjapmn_md.onContentEvent()の、行数390あたり、
apmnSetCookie()という関数で行っています。
*/

(function(){
	rjapmn_md.data = {};

	rjapmn_md.data.posArray = [null, "init"];

	rjapmn_md.data.INTERVAL_FADEIN = 800;
	rjapmn_md.data.INTERVAL_DOOR_TWEEN = 1200;
	rjapmn_md.data.INTERVAL_DOOR_WAIT = 500;
	rjapmn_md.data.KEY = 0;
	
	rjapmn_md.data.loadImgArray = [
		"/static/top/modal/images/bg_modal.png",
		"/static/top/modal/images/img_chara.png",
		"/static/top/modal/images/face_greeting.gif",
		"/static/top/modal/images/face_wink.gif",
		"/static/top/modal/images/img_desk_chair.png",
		"/static/top/modal/images/img_tree.png",
		"/static/top/modal/images/img_pc.png",
		"/static/top/modal/images/img_chair_l.png",
		"/static/top/modal/images/img_door_l.png",
		"/static/top/modal/images/img_door_r.png",
		"/static/top/modal/images/btn_back_off.gif",
		"/static/top/modal/images/btn_search_off.gif",
		"/static/top/modal/images/btn_s1_1_off.gif",
		"/static/top/modal/images/btn_s1_2_off.gif",
		"/static/top/modal/images/btn_s1_3_off.gif",
		"/static/top/modal/images/btn_s1_4_off.gif",
		"/static/top/modal/images/btn_s1_5_off.gif",
		"/static/top/modal/images/btn_s1_6_off.gif",
		"/static/top/modal/images/btn_s1_7_off.gif"
	];

	rjapmn_md.data.is_cookie=false;
	rjapmn_md.data.cookieArray = ['apmnFirstVisitStation','apmnFirstVisitRent','apmnFirstVisitNumbers']

	rjapmn_md.data.btnActiveObj = {"scene1":undefined, "scene2":undefined, "scene3":undefined, "scene4":undefined};
	rjapmn_md.data.dataObj = {"scene1":undefined, "scene1eki":undefined, "scene2":undefined, "scene3":undefined};

	rjapmn_md.data.numbersArray = {
		"0":"ワンルーム/1K/1DK/1LDK/2K/2DK",
		"1":"1LDK/2K/2DK/2LDK/3K/3DK/3LDK",
		"2":"2LDK/3K/3DK/3LDK/4K/4DK/4LDK/5K以上"
	}
	
	//間取り検索用
	rjapmn_md.data.madorisArray = {
		"0":"madori10,madori11,madori12,madori14,madori21,madori22",
		"1":"madori14,madori21,madori22,madori24,madori31,madori32,madori34",
		"2":"madori24,madori31,madori32,madori34,madori41,madori42,madori44,madori51"
	}

	//賃料（検索用）
	rjapmn_md.data.tinryoArray = {
		"0":"0-50000",
		"1":"50000-70000",
		"2":"70000-100000",
		"3":"100000-150000",
		"4":"150000-200000",
		"5":"200000-9999999"
	}
	
	//----------------------------------------------------------------------------
	// INIT - Event
	//----------------------------------------------------------------------------
	rjapmn_md.init = function(){
		rjapmn_md.onLoadMainEvent();
		rjapmn_md.initInputText();

		initCookieVisit();
	}


	//----------------------------------------------------------------------------
	// INIT - ボタン初期化
	//----------------------------------------------------------------------------
	rjapmn_md.initBtnScene = function(){

		//次へボタン
		for(var i=1; i<5; i++){
			initNextAndSearchBtn(i);

			if(i>1){
				//戻るボタン
				initBackBtn(i);
			}

			//各リストボタン(scene2 and scene3)
			if(i>1 && i<4){
				initListBtn(i);
			}
		}

		function initNextAndSearchBtn(i){
			var num = i+1;
				
			$('#scenearea #scene'+i+' .btn-search').on('click', function(e){
				e.preventDefault();

				var now = rjapmn_md.getContent('now');

				if(now == 'scene1'){

					//『質問：住みたい駅名を入力してください』のデータ仮保存
					_value = $('#scene1 input').attr('value');

					//htmlのinputのvalueのテキストと違うものが記述されたかどうか、簡易判別
					//alert($('#input-station').val() + '-' + _value);
					if($('#input-station').val() != _value){
						
						
						//駅名は入力されているが選択されていない場合
						if ($('#input-station').val() != '' && $('#input-val').val() == '')
						{
							//console.log(ajaxstatus);

							if ($('.select_list').children().length == 0)
								$('.scene1-error').show();
								
							return;
						}
						setFirstVisitLoacalData('scene1', $('#input-station').val());
						setFirstVisitLoacalData('scene1eki', $('#input-val').val()); //駅CD保存
						rjapmn_md.setContent("scene2");
					}

				}else if(now == 'scene2'){

					if(rjapmn_md.data.btnActiveObj['scene2'] != undefined){
						rjapmn_md.setContent("scene3");
					}

				}else if(now == 'scene3'){

					if(rjapmn_md.data.btnActiveObj['scene3'] != undefined){
						rjapmn_md.setContent("scene4");
					}

				}else{
					rjapmn_md.setContent("scene"+num);
					
					
					var eki = rjapmn_md.data.dataObj['scene1'];
					var tinryou = rjapmn_md.data.dataObj['scene2'];
					var madori = rjapmn_md.data.dataObj['scene3'];
					
					var items=[];
					
					items.push({name:'search_type',value:'line'}); //路線検索
					//駅検索
					
					var ekis = rjapmn_md.data.dataObj['scene1eki'].split('-'); //駅クッキー値
					var pref = ekis[0];
					var ekiList = ekis[1].split('.'); //複数駅
					for(var index = 0 ; index < ekiList.length; index++){
						items.push({name:'target_'+index, value:pref + '-' + ekiList[index]});
					}
					var eki = $('#scene4-confirm').find('.station').html().split('(')[0];
					CONS.saveSimpleEki(eki + '|' + rjapmn_md.data.dataObj['scene1eki']);
					
					//賃料
					var tinryoLabel = $('#wrapper-confirm').find('li.rent').html();
					var tinryo1 = 0;
					var tinryo2 = 9999999;
					var vals;
					
					//alert(tinryoLabel);
					
					if(tinryoLabel.indexOf('20') > 0){
						vals = rjapmn_md.data.tinryoArray["4"];					
					}
					else if(tinryoLabel.indexOf('15') > 0){
						vals = rjapmn_md.data.tinryoArray["3"];					
					}
					else if(tinryoLabel.indexOf('10') > 0){
						vals = rjapmn_md.data.tinryoArray["2"];					
					}
					else if(tinryoLabel.indexOf('7') > 0){
						vals = rjapmn_md.data.tinryoArray["1"];					
					}
					else if(tinryoLabel.indexOf('5') >= 0){
						vals = rjapmn_md.data.tinryoArray["0"];					
					}
					else if(tinryoLabel.indexOf('20') == 0){
						vals = rjapmn_md.data.tinryoArray["5"];
					}
					if(vals != undefined && vals != ''){
						tinryo1 = vals.split('-')[0];
						tinryo2 = vals.split('-')[1];
						items.push({name:'tinryo1',value:tinryo1});
						items.push({name:'tinryo2',value:tinryo2});
					}					
					
					//間取り
					var numbers = "2";
					if(rjapmn_md.data.dataObj['scene3'].indexOf('1') >= 0) numbers = "0";
					else if(rjapmn_md.data.dataObj['scene3'].indexOf('2') >= 0) numbers = "1";
					
					var madoris = rjapmn_md.data.madorisArray[numbers].split(',');
					for(var index = 0 ; index < madoris.length; index++){
						items.push({name:madoris[index], value:'on'});
					}
					
					items.push({name:'page',value:1}); //ページ１
					
					submit('/rstobi/rstobi','POST',items);
				}	
			});		
		}

		//Submit検索
		function submit(action, method, values) {
	 	   var form = $('<form/>', {
		        action: action,
		        method: method
		    });
		    $.each(values, function() {
		        form.append($('<input/>', {
		            type: 'hidden',
		            name: this.name,
		            value: this.value
		        }));    
		    });
		    form.appendTo('body').submit();
		}
		
		function initBackBtn(i){
			var num = i-1;
			$('#scenearea #scene'+i+' .btn-back').on('click', function(e){
				e.preventDefault();
				
				rjapmn_md.setContent("scene"+num);
			});		
		}

		function initListBtn(i){
			$('#scenearea #scene'+i+' li a').on('click', function(e){
				e.preventDefault();
				var num = $('#scenearea #scene'+i+' li a').index(this);

				if(rjapmn_md.data.btnActiveObj['scene'+i] != num){
					if(rjapmn_md.data.btnActiveObj['scene'+i] != undefined){
						var pre_li = $('#scenearea #scene'+i+' li a:eq('+rjapmn_md.data.btnActiveObj['scene'+i]+')');
						// pre_li.addClass('mover');

						rjapmn_md.onImgClickReplace.off($('img',pre_li));

						pre_li.parent().addClass('mover');
					}
					rjapmn_md.data.btnActiveObj['scene'+i] = num;
					rjapmn_md.onImgClickReplace.on($('img',this));

					//クリックされたボタンの'alt'テキストをデータとして、rjapmn_md.data.dataObjに登録します。
					//altテキストでなく、他に任意のデータを登録したい場合は、下記、代入する値を変更してください。
					var _scene = 'scene'+i;
					setFirstVisitLoacalData(_scene, $('#'+_scene+' li a:eq('+rjapmn_md.data.btnActiveObj[_scene]+') img').attr('alt'));

					$(this).parent().removeClass('mover');
				}
			});	
		}

		//『質問：ご希望の家賃を選んでください』『質問：居住人数を選んでください』のデータ仮保存
		function setFirstVisitLoacalData(_scene, obj){
			rjapmn_md.data.dataObj[_scene] = obj;
		}
	}

	//----------------------------------------------------------------------------
	// BTN - Click Replace
	//----------------------------------------------------------------------------
	rjapmn_md.onImgClickReplace = {
		on:function(obj){obj.attr('src', obj.attr('src').replace('_off', '_stay'));},
		off:function(obj){obj.attr('src', obj.attr('src').replace('_stay', '_off'));}
	}

	//----------------------------------------------------------------------------
	// BTN - Check Active
	//----------------------------------------------------------------------------
	rjapmn_md.checkBtnActive = function(){
		var now = rjapmn_md.getContent('now');
		var num = rjapmn_md.data.btnActiveObj[now];

		if(num != undefined){
			var _scene = $('img', '#scenearea #'+now+' li:eq('+num+')');
			_scene.attr('src', _scene.attr('src').replace('_off', '_stay'));
		}
	}

	//----------------------------------------------------------------------------
	// EVENT - MAIN
	//----------------------------------------------------------------------------
	rjapmn_md.onContentEvent = function(str){

		var pre = rjapmn_md.getContent('pre');
		var now = str;

		switch(now){
			case "opening":
			
				//loader削除
				rjapmn.onLoadingEvent.complete();

				//各ボタンINITしたら、display:noneにしないと
				rjapmn_md.initBtnScene();

				//----------------------------------
				//DISPLAY NONE;
				//----------------------------------
				for(var k=2;k<5;k++){$('#scene'+k).css({display:'none'})}

				$("#firstwrapper #contents-md").css({display:"block"})
				//top.js
				.animate({
					opacity:1 
				}, rjapmn_md.data.INTERVAL_FADEIN, "easeOutQuart", function() {
					rjapmn_md.setContent("doorOpen");
				});
			break;

			case "doorOpen":
				$("#door_l").delay(rjapmn_md.data.INTERVAL_DOOR_WAIT).animate({marginLeft:"-470px" }, rjapmn_md.data.INTERVAL_DOOR_TWEEN, "easeOutExpo", function() {});
				$("#door_r").delay(rjapmn_md.data.INTERVAL_DOOR_WAIT).animate({marginLeft:"930px" }, rjapmn_md.data.INTERVAL_DOOR_TWEEN, "easeOutExpo", function() {
					rjapmn_md.setContent("greeting");
				});
			break;

			case "greeting":

				$('#greeting').css({display:'block', opacity:1});

				$('#greeting .fukidashi img')
				.css({width:'10px', height:'10px', opacity:1})
				.animate({width:'252px', height:'150px'}, 400, "easeOutQuint");

				$('#greeting .com_greeting')
				.delay(500)
				.animate({opacity:'1'}, 600, "easeOutQuint");

				$('#greeting')
				.delay(2000)
				.animate({opacity:0}, 300, "easeOutQuart", function() {
					$('#greeting').css({display:'none'})
					rjapmn_md.setContent("scene1");
				});

			break;

			case "scene1":

				if(pre == "greeting"){
					$('#chara').delay(50).animate({marginLeft:'190px'}, 700, "easeOutCubic");
					$('#facearea').delay(50).animate({left:'239px'}, 700, "easeOutCubic");
					$('#tree').delay(100).animate({marginLeft:'-78px'}, 800, "easeOutCubic");
					$('#pc').animate({marginLeft:'20px'}, 600, "easeOutCubic");
					$('#chair_l').animate({marginLeft:'-120px'}, 600, "easeOutCubic");

					//質問スライドイン
					$('#md-quest').delay(100).animate({left:'436px'}, 700, "easeOutQuart");


					rjapmn_md.onCommentShowHide('scene1', true);
					rjapmn_md.onFaceAnimEvent('greeting');


				}else if(pre == "scene2"){
					$('#scene2')
					.animate({marginLeft:'-450px'}, 400, "easeOutQuart", function() {
						$('#scene2').css({marginLeft:0, display:'none'});
					});

					$('#scene1').css({display:'block',marginLeft:'450px'})
					.animate({marginLeft:'0px'}, 400, "easeOutQuart", function() {
						rjapmn_md.checkBtnActive();
					});

					rjapmn_md.onCommentShowHide(pre, false);
					rjapmn_md.onCommentShowHide(now, true);
				}
			break;

			case "scene2":

				if(pre == "scene1"){
					$('#scene1')
					.animate({marginLeft:'-450px'}, 400, "easeOutQuart", function() {
						$('#scene1').css({marginLeft:'0px', display:'none'});
					});

					$('#scene2').css({display:'block',marginLeft:'450px'})
					.animate({marginLeft:'0px'}, 400, "easeOutQuart", function() {
						rjapmn_md.checkBtnActive();
					});

				}else if(pre =="scene3"){

					$('#scene3')
					.animate({marginLeft:'-450px'}, 400, "easeOutQuart", function() {
						$('#scene3').css({marginLeft:'0px', display:'none'});
					});

					$('#scene2').css({display:'block',marginLeft:'450px'})
					.animate({marginLeft:0}, 400, "easeOutQuart", function() {
						rjapmn_md.checkBtnActive();
					});

				}

				rjapmn_md.onCommentShowHide(pre, false);
				rjapmn_md.onCommentShowHide(now, true);
			break;

			case "scene3":

				if(pre == "scene2"){
					$('#scene2')
					.animate({marginLeft:'-450px'}, 400, "easeOutQuart", function() {
						$('#scene2').css({marginLeft:0, display:'none'});
					});

					$('#scene3').css({display:'block',marginLeft:'450px'})
					.animate({marginLeft:'0px'}, 400, "easeOutQuart", function() {
						rjapmn_md.checkBtnActive();
					});

				}else if(pre =="scene4"){
					$('#scene4').animate({marginLeft:'-450px'}, 400, "easeOutQuart", function() {
						$('#scene4').css({marginLeft:'0px', display:'none'});
					});

					$('#scene3').css({display:'block',marginLeft:'450px'})
					.animate({marginLeft:'0px'}, 400, "easeOutQuart", function() {
						rjapmn_md.checkBtnActive();
						rjapmn_md.onFaceAnimEvent('greeting');
					});
				}

				rjapmn_md.onCommentShowHide(pre, false);
				rjapmn_md.onCommentShowHide(now, true);
			break;

			case "scene4":

				if(pre == "scene3"){
					$('#scene3')
					.animate({marginLeft:'-450px'}, 400, "easeOutQuart", function() {
						$('#scene3').css({marginLeft:0, display:'none'});
					});

					$('#scene4').css({display:'block',marginLeft:'450px'});

					rjapmn_md.onCreateScene4Html();

					$('#scene4').animate({marginLeft:'0px'}, 400, "easeOutQuart", function() {
						
						rjapmn_md.onFaceAnimEvent('wink');
						
						if(rjapmn_md.data.btnActiveObj["scene4"] == undefined){
							rjapmn_md.data.btnActiveObj["scene4"] = true;
							rjapmn_md.onFaceAnimEvent('wink');
						}
					});
				}

				rjapmn_md.onCommentShowHide(pre, false);
				rjapmn_md.onCommentShowHide(now, true);
			break;

			case "scene5":

				//alert("駅名：今はなし /"+"家賃："+rjapmn_md.data.dataObj['scene2']+"/居住人数："+rjapmn_md.data.dataObj['scene3']);
				apmnSetCookie(rjapmn_md.data.cookieArray[0],rjapmn_md.data.dataObj['scene1']);
				apmnSetCookie(rjapmn_md.data.cookieArray[1],rjapmn_md.data.dataObj['scene2']);
				apmnSetCookie(rjapmn_md.data.cookieArray[2],rjapmn_md.data.dataObj['scene3']);


				//alert("Cookie/駅名="+getFirstVisitCookieStation());
				//alert("Cookie/家賃="+getFirstVisitCookieRent());
				//alert("Cookie/居住人数="+getFirstVisitCookieNumbers());

				rjapmn_md.onCommentShowHide(pre, false);
				rjapmn_md.onCommentShowHide(now, true);
				
			break;
		}
	}

	rjapmn_md.onCreateScene4Html = function(){
		$('#wrapper-confirm').remove();
		$('#scene4-confirm').prepend(rjapmn_md.getHtmlScene4Source());
	}

	rjapmn_md.getHtmlScene4Source = function(){
		
		var numbers = "2";
		if(rjapmn_md.data.dataObj['scene3'].indexOf('1') >= 0) numbers = "0";
		else if(rjapmn_md.data.dataObj['scene3'].indexOf('2') >= 0) numbers = "1";
		
		var _source="";
		_source +='<div id="wrapper-confirm">';
		_source += '<ul>';
		_source += '<li class="station">'+rjapmn_md.data.dataObj['scene1']+'</li>';
		_source += '<li class="rent">'+rjapmn_md.data.dataObj['scene2']+'</li>';
		_source += '<li class="numbers">'+rjapmn_md.data.dataObj['scene3']+'<span class="araeofroom">'+rjapmn_md.data.numbersArray[numbers] +'</span></li>';
		_source += '</ul>';
		_source += '</div>';

		return _source;
	}

	//----------------------------------------------------------------------------
	// LOAD
	//----------------------------------------------------------------------------
	rjapmn_md.onLoadMainEvent = function(){
		var len = rjapmn_md.data.loadImgArray.length;
		rjapmn_md.data.loadcount = len;

		for(var i=0; i<len; i++){
			rjapmn_md.loaderUtil.init(i, rjapmn_md.data.loadImgArray[i], rjapmn_md, "onLoadMainComplete");
		}
	}

	rjapmn_md.onLoadMainComplete = function(){
	    	rjapmn_md.data.loadcount--;
	    	if(rjapmn_md.data.loadcount == 0){
	    		rjapmn_md.setContent("opening");
	    	}
	}

	rjapmn_md.loaderUtil={
		_scope:[],
		_callback:"",
		_imgArray:[],
		
		init:function(num,url,scope,func){
			this._scope[0]=scope;
			this._callback=func;
			this._imgArray[num]=new Image();
			this._imgArray[num].onload=rjapmn_md.loaderUtil.onComplete;
			this._imgArray[num].src=url;
		},

		onComplete:function(){
			(function(){rjapmn_md.loaderUtil._scope[0][rjapmn_md.loaderUtil._callback]()})();
		}
	}

	//----------------------------------------------------------------------------
	// INIT - Cookie Visit
	//----------------------------------------------------------------------------
	function initCookieVisit(){
		if (navigator.cookieEnabled) {
			rjapmn_md.data.is_cookie = true;
		}else {
			//You can't cookie
		}
	}
	
	function countJapaneseString(str) { 
	    var r = 0; 
	    for (var i = 0; i < str.length; i++) { 
	        var c = str.charCodeAt(i); 
	        // Shift_JIS: 0x0 ～ 0x80, 0xa0 , 0xa1 ～ 0xdf , 0xfd ～ 0xff 
	        // Unicode : 0x0 ～ 0x80, 0xf8f0, 0xff61 ～ 0xff9f, 0xf8f1 ～ 0xf8f3 
	        if ( (c >= 0x0 && c < 0x81) || (c == 0xf8f0) || (c >= 0xff61 && c < 0xffa0) || (c >= 0xf8f1 && c < 0xf8f4)) { 
	            //r += 1; //全角文字だけカウントする。
	        } else { 
	            r += 1; 
	        } 
	    } 

	    return r; 
	} 
	//ajax実行状況 0=待機、1=実行中
	var ajaxstatus = 0;
	rjapmn_md.AjaxEkiSearch = function(keyword)
	{
		if (keyword == undefined || keyword == '' || countJapaneseString(keyword) < 2)
			return;

		if (ajaxstatus != 0)
			return;
		
		ajaxstatus = 1;
		$.ajax({
			beforeSend: function(xhr){
		    	 xhr.overrideMimeType("text/html;charset=UTF-8");
			},
			type: 'POST',
			url: '/areaajax/geteki/',
			dataType: 'text',
			data:{eki:keyword,likeop:"1"},
			success: function(data) {
//				console.log(keyword + ":" + data);
				ajaxstatus = 0;
				if ($("#input-station").val() != keyword)
				{
					rjapmn_md.AjaxEkiSearch($("#input-station").val());
					return;
				}
				if(data != undefined && data != '' && $.trim(data).length > 0){
					$('.select_list').empty();
					
					//データフォーマット駅（都道府県）|都道府県CDー駅CD;...								
					  var vals = data.split(';');								  								  
					  for(var i = 0; i < vals.length; i++){
						  var splitVals = vals[i].split('|');
						  $('.select_list').append('<li><a href="javascript:void(0)" onclick="rjapmn_md.selectEki('+ "'" + $.trim(splitVals[0]) + "','" + $.trim(splitVals[1]) + "')" + '"' + '>' + $.trim(splitVals[0]) + '</a></li>')
						  
						  if (vals.length == 1)
						  {
							  //★★★
							  //alert(splitVals[1].trim());
							  //rjapmn_md.selectEki($.trim(splitVals[0]), $.trim(splitVals[1]));
						  }
					  }
					  
					  if (vals.length >= 1) $('.select_list').show(); //★★★
					  
					  
					  $('.scene1-error').hide();
				}
				
			},
			error:function() {
				$('.select_list').empty();
				$('.select_list').hide();
			}
		});
		
	}

	//駅検索テキストボックス
	$('#input-station').on('propertychange input', function(e){
		
		if(rjapmn_md.data.KEY == e.keyCode || e.keyCode == 32)
			return;
		
		
		//テキストボックスが変更されたらClear
		if 	($('#input-eki').val() != $(this).val())
		{
			$('.select_list').empty();
			$('.select_list').hide();
			
			$('#input-eki').val('');
			$('#input-val').val('');
		}
		
		//4byte以上→検索
		if(countJapaneseString($(this).val()) > 1){	
			$('.scene1-error').hide();
			$('.select_list').empty();
			rjapmn_md.AjaxEkiSearch($(this).val());
		}

		return false;
	});
	/**
	* Cookie - get data
	*/
	function getFirstVisitCookieStation(){return apmnGetCookie(rjapmn_md.data.cookieArray[0]);}
	function getFirstVisitCookieRent(){return apmnGetCookie(rjapmn_md.data.cookieArray[1]);}
	function getFirstVisitCookieNumbers(){return apmnGetCookie(rjapmn_md.data.cookieArray[2]);}

	/**
	* Cookie - get data
	*/
	function apmnGetCookie(str){
		var result = null;
		var cookieName=str+'=';
		var allcookies = document.cookie;

		var position = allcookies.indexOf(cookieName);

		if(position != -1){
			var startIndex = position + cookieName.length;
			var endIndex = allcookies.indexOf(';',startIndex);

			if(endIndex == -1){
				endIndex = allcookies.length;
			}
			result = decodeURIComponent(allcookies.substring(startIndex, endIndex));
		}
		return result;
	}

	function apmnSetCookie(_obj, _data){
		if(rjapmn_md.data.is_cookie){
			document.cookie = _obj +'=' + _data + apmnCreateDateControl(1);
		}
	}

	/**
	* Cookie - delete
	*/
	function apmnDeleteCookie(obj) {
		cName = obj+'=';
		document.cookie = cName  + apmnCreateDateControl(-1);
	}

	/**
	* Create date
	*/
	function apmnCreateDateControl(dir){
		var str="";
		var expires;
		var nowtime = new Date().getTime();
		
		expires = new Date(nowtime + (60 * 60 * 24 * 1000 * 3 * dir));
		//expires = new Date(nowtime + (60 * 60 * 24 * 1000 * dir));
		
		expires = expires.toGMTString();
		str += "; expires=" + expires;
		return str;
	}

	//---------------------------------------------------------------------------
	//Event - onContentEvent
	//---------------------------------------------------------------------------
	rjapmn_md.setContent = function(obj){
		rjapmn_md.data.posArray.shift();
		rjapmn_md.data.posArray.push(obj);

		rjapmn_md.onContentEvent(rjapmn_md.data.posArray[1]);
	},

	rjapmn_md.getContent = function(str){
		var _str;
		if(str == "pre")_str = rjapmn_md.data.posArray[0];
		else if(str == "now")_str = rjapmn_md.data.posArray[1];

		return _str;
	}

	//----------------------------------------------------------------------------
	// EVENT - コメントとキャラ表情の変更
	//----------------------------------------------------------------------------
	rjapmn_md.onCommentShowHide = function(_scene, b){
		if(b){
			$('#comarea .com_'+_scene).css({display:'block'})
				.delay(500)
				.animate({opacity:1}, 700, "easeOutQuart");
		}else{
			$('#comarea .com_'+_scene)
				.animate({opacity:0}, 300, "easeOutQuart")
				.css({display:'none'});
		}
	}

	rjapmn_md.onFaceAnimEvent = function(_scene){
		$('#face_scene').remove();
		$('#facearea').prepend(rjapmn_md.getHtmlFaceareaSource(_scene));
	}

	rjapmn_md.getHtmlFaceareaSource = function(_scene){
		var _source="";
		_source +='<div id="face_scene">';
		_source += '<img src="/static/top/modal/images/face_'+_scene+'.gif" width="130" height="92" alt="" />';
		_source += '</div>';

		return _source;
	}

	//---------------------------------------------------------------------------
	//　initInputText
	//---------------------------------------------------------------------------
	rjapmn_md.initInputText = function(){
		var inputTextBox = $('#questarea input:text');

		inputTextBox.each(function(i){
			$(this).focus(function(e){
				$(this).addClass('input-focus');
				if(this.value == this.defaultValue){
					$(this).val('');
				};
			}).blur(function(e){
				if(this.value == ''){
					$(this).val(this.defaultValue).removeClass('input-focus');
				};
			});
			if (this.value != this.defaultValue) {
				$(this).addClass('input-focus');
			};
		});
	};
	
	//駅選択イベント
	rjapmn_md.selectEki = function(name, val){
		$('#input-eki').val(name);
		$('#input-val').val(val);
		$('#input-station').val(name);
		$('.select_list').hide();
	}
	
})();

//----------------------------------------------------------------------------
// INIT
//----------------------------------------------------------------------------
$(document).ready(
	function(){
		rjapmn_md.init();
	}
);
